package com.ui.controls
{
	import com.ui.core.ScaleMode;
	import com.ui.core.UIComponent;
	import com.ui.data.ValueLabelData;

	/**
	 * @author Cafe
	 */
	public class ValueLabel extends UIComponent
	{
		protected var _data : ValueLabelData;
		protected var _nameLabel : Label;
		protected var _valueLabel : Label;
		private var _updownMode : Boolean = false;

		public function ValueLabel( data : ValueLabelData )
		{
			_data = data;
			super( _data );
		}

		override protected function layout() : void
		{
			if (_updownMode)
			{
				_valueLabel.x = (_nameLabel.icon.width * _nameLabel.icon.scaleX - _valueLabel.textWidth) / 2;
				_valueLabel.y = _nameLabel.height * _nameLabel.icon.scaleY + _data.nameLableData.padding;
			}
			else
			{
				_valueLabel.x = _nameLabel.width + _data.valueLableData.padding;
				_valueLabel.y = _nameLabel.y;
			}
			if (_data.scaleMode == ScaleMode.SCALE_NONE)
			{
				_valueLabel.moveTo( _data.valueLableData.x, _data.valueLableData.y );
				_nameLabel.moveTo( _data.nameLableData.x, _data.nameLableData.y );
			}
		}

		override protected function create() : void
		{
			_nameLabel = new Label( _data.nameLableData );
			_valueLabel = new Label( _data.valueLableData );
			addChild( _nameLabel );
			addChild( _valueLabel );
			layout();
		}

		public function get value() : String
		{
			return _valueLabel.text;
		}

		public function set value( value : String ) : void
		{
			_valueLabel.htmlText = value;
		}

		public function get nameText() : String
		{
			return _nameLabel.text;
		}

		public function set nameText( value : String ) : void
		{
			_nameLabel.text = value;
			layout();
		}

		public function set nameToolTipSource( value : * ) : void
		{
			_data.nameLableData.toolTipData.source = value;
			if (_nameLabel.toolTip && _nameLabel.toolTip.parent)
				_nameLabel.toolTip.source = value;
		}

		public function set valueToolTipSource( value : * ) : void
		{
			_data.valueLableData.toolTipData.source = value;
			if (_valueLabel.toolTip && _valueLabel.toolTip.parent)
				_valueLabel.toolTip.source = value;
		}

		public function get nameLabel() : Label
		{
			return _nameLabel;
		}

		public function get valueLabel() : Label
		{
			return _valueLabel;
		}

		public function set updownMode( updownMode : Boolean ) : void
		{
			_updownMode = updownMode;
			layout();
		}
	}
}
